﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DormMS.IService;
using DormMS.Model;
using DormMS.Model.SearchModels;

namespace DormMS.Controllers
{
    public class ProductCategoryController : BaseController
    {
        protected IProductCategoryService categoryservice;
        public ProductCategoryController(IUserInfoService s, IProductCategoryService _categoryservice) : base(s)
        {
            categoryservice = _categoryservice;
        }

        /// <summary>
        /// 产品分类
        /// </summary>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole ="13")]
        [HttpGet]
        public ActionResult ProductCategoryManage()
        {
            return View();
        }

        /// <summary>
        /// 产品分类分页数据
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "13")]
        [HttpPost]
        public ActionResult ProductCategoryManage(ProductCategorySearchModel search)
        {
            int total = 0;
            string parentname = "";
            var list = categoryservice.ProductCategoryManage(search, out total, out parentname);
            return Json(new { Total = total, Results = list, ParentName = parentname });
        }

        /// <summary>
        /// 设为热门
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "13")]
        [HttpPost]
        public ActionResult ChangeCategoryState(int Id)
        {
            return Json(new { Hot = categoryservice.ChangeCategoryState(Id, CurrentLoginUser.Id) });
        }

        /// <summary>
        /// 新增、编辑保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "13")]
        [HttpPost]
        public ActionResult UpdateCategory(Product_Category model)
        {
            return Json(categoryservice.UpdateCategory(model, CurrentLoginUser.Id));
        }

        /// <summary>
        /// 删除分类
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "13")]
        [HttpPost]
        public ActionResult DelCategory(int Id)
        {
            return Json(categoryservice.DelCategory(Id, CurrentLoginUser.Id));
        }

        /// <summary>
        /// 获取产品分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCategoryList()
        {
            return Json(categoryservice.GetCategoryList());
        }

    }
}